import { Route, Redirect, Switch } from 'react-router-dom';
import 'antd/dist/antd.css'
import Login from './pages/login';
import Reg from './pages/regist';
import Subject from './pages/subject/Subject';
import Student from './pages/student/Student'
import Admin from './pages/admin/Admin';
import SuperAdmin from './pages/superAdmin/SuperAdmin';
import Error from './pages/pubilc/error';

function App() {
  // 验证用户身份
  const verify = userInfo => {
    switch (userInfo.role) {
      case 'student':
        return <Student userInfo={userInfo} />;
      case 'admin':
        return <Admin userInfo={userInfo} />;
      case 'superAdmin':
        return <SuperAdmin userInfo={userInfo} />;
      default:
        return <Redirect to="/login"></Redirect>
    }
  }
  return (
    <Switch>
      <Route path="/login" component={Login}></Route>
      <Route path="/reg" component={Reg}></Route>
      <Route path="/subject">
        <Subject render={verify}></Subject>
      </Route>
      <Redirect from="/" to="/login"></Redirect>
      <Route component={Error}></Route>
    </Switch>
  );
}

export default App;
